package com.michael.demos.springboot.satoken.config;

import cn.dev33.satoken.stp.StpInterface;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * 类功能描述:
 * <pre>
 *   自定义用户权限处理
 * </pre>
 *
 * @author Michael
 * @version 1.0
 * @date 2021/6/25 16:31
 */
@Component
public class MyAuth implements StpInterface {

    @Override
    public List<String> getPermissionList(Object userId, String s) {
        if (1000L == Long.parseLong(userId.toString())) {
            return Arrays.asList("user-add", "user-del", "user-list");
        } else if (2000L == Long.parseLong(userId.toString())) {
            return Arrays.asList("user-add");
        }

        return null;
    }

    @Override
    public List<String> getRoleList(Object userId, String s) {
        if (1000L == Long.parseLong(userId.toString())) {
            return Arrays.asList("admin");
        } else if (2000L == Long.parseLong(userId.toString())) {
            return Arrays.asList("dev");
        }

        return null;
    }
}
